package com.usian.controller;

import com.usian.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class HelloController {
    @RequestMapping("/hello")
    public String hello(Model model){
        model.addAttribute("name","小猪");
        model.addAttribute("sex","男");
        model.addAttribute("birth",new Date());
        model.addAttribute("msg","123456789");
        List<User> userList=new ArrayList<>();
        userList.add(new User("猪猪",1,"男"));
        userList.add(new User("猪猪猪",2,"男"));
        userList.add(new User("女猪猪",3,"女"));
        model.addAttribute("list",userList);
        return "hello";
    }
    @RequestMapping("abc")
    @ResponseBody
    public String abc(Integer id,String name){
        return id+"-----"+name;
    }
    @RequestMapping("abc1/{id}/{name}")
    @ResponseBody
    public String abc1(@PathVariable Integer id, @PathVariable String name){
        return id+"-----"+name;
    }
    @RequestMapping("abc2/{id}")
    @ResponseBody
    public String abc2(@PathVariable Integer id,String name){
        return id+"-----"+name;
    }
    @RequestMapping("request")
    public String request(HttpServletRequest request, HttpSession session){
        request.setAttribute("request","request");
        session.setAttribute("session","session");
        return "request";
    }
}
